package xin.val1ant.spring_security_jpa.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * 主页控制器.
 *
 */
@Controller
public class MainController {
	private static final Logger logger  = LoggerFactory.getLogger(MainController.class);
	
	@GetMapping("/")
	public String root() {
		logger.info("拦截到 / 请求");
		return "redirect:/index";
	}

	@GetMapping("/hello")
	public String hello(){
		logger.info("拦截到 /hello 请求");
		return "hello";
	}
	@GetMapping("/index")
	public String index() {
		return "index";
	}

	@GetMapping("/login")
	public String login() {
		return "login";
	}

	@GetMapping("/login-error")
	public String loginError(Model model) {
		model.addAttribute("loginError", true);
		model.addAttribute("errorMsg", "登陆失败，用户名或者密码错误！");
		return "login";
	}

    @GetMapping("/403")
    public String accesssDenied() {
        return "403";
    }
}
